<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <!-- 字典表查询 -->
          <a-col :md="4" :sm="6">
            <a-form-item label="审核">
              <j-dict-select-tag v-model="queryParam.audit" placeholder="请选择审核状态" dictCode="audit_status"></j-dict-select-tag>
            </a-form-item>
          </a-col>
          <!-- 字典表查询 -->
          <a-col :md="4" :sm="6">
            <a-form-item label="投诉">
              <j-dict-select-tag v-model="queryParam.type" placeholder="请选择投诉状态" dictCode="complain_status"></j-dict-select-tag>
            </a-form-item>
          </a-col>
          
          <a-col :md="4" :sm="6">
            <a-form-item label="用户昵称" :labelCol="{span: 5}" :wrapperCol="{span: 18, offset: 1}">
              <j-input placeholder v-model="queryParam.nicakname"></j-input>
            </a-form-item>
          </a-col>
          
            <a-col :md="4" :sm="6">
            <a-form-item label="学校名称" :labelCol="{span: 5}" :wrapperCol="{span: 18, offset: 1}">
              <j-input placeholder v-model="queryParam.schoolName"></j-input>
            </a-form-item>
          </a-col>
          
          <a-col :md="4" :sm="6">
            <a-form-item label="用户ID" :labelCol="{span: 5}" :wrapperCol="{span: 18, offset: 1}">
              <j-input placeholder v-model="queryParam.userId"></j-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-button type="primary" @click="searchQuery" icon="search" style="margin-left: 21px">查询</a-button>
            <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-dropdown v-if="selectedRowKeys.length > 0">
<!--        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete" />删除</a-menu-item>
        </a-menu> -->
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down" />
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table ref="table" size="middle" :scroll="{x:true}" bordered rowKey="id" :columns="columns" :dataSource="dataSource"
        :pagination="ipagination" :loading="loading" :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap" @change="handleTableChange">

        <template slot="avatarslot" slot-scope="text, record">
          <div class="anty-img-wrap">
            <a-avatar shape="square" :src="getAvatarView(record.avatar)" icon="logo" />
          </div>
        </template>
        
        <template slot="piclot" slot-scope="text, record">
            <a  v-if="record.dynamicVideo" :href="record.dynamicVideo">
              <img :src="record.dynamicVideo +'?x-oss-process=video/snapshot,t_7000,f_jpg,w_1000,h_800,m_fast' "  width="200" height="140" />
            </a>
        
            <!-- 多张图片只展示第一张  viewer 中展示全部   -->
            <viewer v-if="record.dynamicImg" :images="record.dynamicImg.split(',')" >
            <a v-for="(src,index) in record.dynamicImg.split(',')">
                <!-- <img :src="src" width="150" height="140" v-if="index == 0"/> -->
                <img :src="src" width="150" height="140" v-if="index == 0"/>
                <img :src="src" width="150" height="140" v-if="index > 0" hidden/>
                <br v-if="index%3 == 2" />
            </a>
            </viewer>
        
        </template>

        <!--        <template slot="htmlSlot" slot-scope="text">
            <div v-html="text"></div>
          </template>
          <template slot="imgSlot" slot-scope="text">
            <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
            <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
          </template>
          <template slot="fileSlot" slot-scope="text">
            <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
            <a-button
              v-else
              :ghost="true"
              type="primary"
              icon="download"
              size="small"
              @click="downloadFile(text)">
              下载
            </a-button>
          </template> -->

        <span slot="action" slot-scope="text, record">

            <!-- //1:待审核  2:审核通过  3:审核不通过 -->
<!--          <span>
             <a-switch :default-checked="false" @change='onChange($event,record)' v-if="record.audit== 3"/>
             <a-switch :default-checked="true" @change='onChange($event,record)' v-if="record.audit== 2"/>
             <a-switch :default-checked="false" @change='onChange($event,record)' v-if="record.audit== 1"/>
          </span> -->

          <span v-if="record.type == 2">
            <a-divider type="vertical" />
            <a-dropdown>
              <a class="ant-dropdown-link">投诉审核
                <a-icon type="down" /></a>
              <a-menu slot="overlay">
                <a-menu-item>
                  <a @click="complaintsNPass(record)">关小黑屋</a>
                </a-menu-item>
                <a-menu-item>
                  <a @click="complaintsPass(record)">放行</a>
                </a-menu-item>
              </a-menu>
            </a-dropdown>
          </span>

          <span v-if="record.recommendedFlag == 2">
            <a-divider type="vertical" />
            <a @click="setRecommended(record)">设为推荐</a>
          </span>

          <span v-if="record.recommendedFlag == 1">
            <a-divider type="vertical" />
            <a @click="cancelRecommended(record)">取消推荐</a>
          </span>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多
              <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                   <a @click="getDynamicInfo(record)">详情</a>
              </a-menu-item>
<!--              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item> -->
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>
    <dynamic-modal ref="modalForm" @ok="modalFormOk" sync></dynamic-modal>

    <!-- //////////////////查看图片对话框  开始////////// -->
    <a-modal title="图片/视频内容" v-model="visible" @ok="imgOk">
      <div v-if="this.imgs != null && this.imgs != ''">
        <viewer v-for="img in imgs" :key="img">
          <img :src="img"  width="100%"/>
        </viewer>
      </div>
      <div v-if="video != ''">
        <a :href="video" target="_blank">
          <img :src="video + '?x-oss-process=video/snapshot,t_7000,f_jpg,w_1000,h_800,m_fast'" width="60" height="60" />
        </a>
      </div>

    </a-modal>
    <!-- //////////////////查看图片对话框   结束////////////// -->

    <!-- 动态详情 -->
    <a-modal v-model="dynamicInfoVisible" title="动态详情" @ok="handleOk">
      <p>头像: &nbsp;
        <a-avatar :src="this.dynamicInfo.avatar" />
        <p>
          <p>用户昵称: &nbsp;{{dynamicInfo.nicakname}}</p>
          <p>ID: &nbsp; {{dynamicInfo.userId}}</p>
          <p>学校: &nbsp; {{dynamicInfo.schoolName}}</p>
          <p>发布时间: &nbsp; {{dynamicInfo.createTime}} </p>
          <p>转发理由: &nbsp; {{dynamicInfo.dynamicContent}}</p>
          
          <p v-if="forwradDynamicInfo.dynamicContent">动态内容: &nbsp; {{forwradDynamicInfo.dynamicContent}}</p>
          
          <div v-if="dynamicInfo.dynamicVideo != '' && dynamicInfo.dynamicVideo != null">
            视频: &nbsp;
            <a :href="forwradDynamicInfo.dynamicVideo">
              <img :src="forwradDynamicInfo.dynamicVideo +'?x-oss-process=video/snapshot,t_7000,f_jpg,w_1000,h_800,m_fast' "  width="200" height="140" />
            </a>
           </div>
           
            <div  v-if="forwradDynamicInfo.dynamicImg">
              图片: &nbsp;
              <div v-for="documentImg in forwradDynamicInfo.dynamicImg.split(',')">
                <viewer>
                  <img :src="documentImg" width="200" height="140" />
                </viewer>
              </div>
            </div>
           <!-- 动态审核：1待审核，2审核通过，3审核不通过 -->
          <p>点赞数: &nbsp; {{dynamicInfo.likeNum}}</p>
          <p>转发数: &nbsp; {{dynamicInfo.shareNum}}</p>
          <p v-if="dynamicInfo.audit == '1'">
            审核状态: &nbsp; 待审核
          </p>
          <p v-if="dynamicInfo.audit == '2'">
            审核状态: &nbsp; 审核通过
          </p>
          <p v-if="dynamicInfo.audit == '3'">
            审核状态: &nbsp; 不通过
          </p>
    </a-modal>


  </a-card>
</template>

<script>
  import '@/assets/less/TableExpand.less'
  import {
    mixinDevice
  } from '@/utils/mixin'
  import {
    JeecgListMixin
  } from '@/mixins/JeecgListMixin'
  import {
    putAction,
    getFileAccessHttpUrl,
    getAction
  } from '@/api/manage'
  import DynamicModal from './modules/DynamicModal'
  import JInput from '@comp/jeecg/JInput'


  export default {
    name: "DynamicList",
    mixins: [JeecgListMixin, mixinDevice],
    components: {
      DynamicModal,
      JInput
    },
    data() {
      return {
        video: '',
        dynamicInfo: {},
        forwradDynamicInfo: {},
        imgs: [],
        dynamicImg:[],
        visible: false,
        dynamicInfoVisible: false,
        confirmLoading: false,
        description: '动态管理表管理页面',
        // 表头
        columns: [{
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: "center",
            customRender: function(t, r, index) {
              return parseInt(index) + 1;
            }
          },
          /* {
            title:'手机号',
            align:"center",
            dataIndex: 'phone'
          },
          {
            title:'用户ID',
            align:"center",
            dataIndex: 'userId'
          },*/
          {
            title: '头像',
            align: "center",
            dataIndex: 'avatar',
            width: 120,
            scopedSlots: {
              customRender: 'avatarslot'
            }
          },
          {
            title: '用户昵称',
            align: "center",
            dataIndex: 'nicakname'
          },
          {
            title: 'ID',
            align: "center",
            dataIndex: 'userId'
          },
          {
            title: '学校',
            align: "center",
            dataIndex: 'schoolName'
          },
          {
            title: '转发时间',
            align: 'center',
            dataIndex: 'createTime'
          },
          {
            title: '转发理由',
            align: "center",
            dataIndex: 'dynamicContent'
          },
          // {
          //   title: '动态图片或视频',
          //   align: "center",
          //   dataIndex: 'dynamicImg',
          //   scopedSlots: {
          //     customRender: 'piclot'
          //   }
          // },
          {
            title: '审核状态',
            align: "center",
            dataIndex: 'audit_dictText'
          },
          {
            title: '投诉状态',
            align: "center",
            dataIndex: 'type_dictText'
          },
          // {
          //   title: '删除状态',
          //   align: "center",
          //   dataIndex: 'delFlag_dictText'
          // },
          {
            title: '推荐状态',
            align: "center",
            dataIndex: 'recommendedFlag_dictText'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: "center",
            fixed: "right",
            width: 147,
            scopedSlots: {
              customRender: 'action'
            }
          }
        ],
        url: {
          list: "/dynamic/dynamic/forWardList",
          delete: "/dynamic/dynamic/delete",
          deleteBatch: "/dynamic/dynamic/deleteBatch",
          exportXlsUrl: "/dynamic/dynamic/exportXls",
          importExcelUrl: "dynamic/dynamic/importExcel",

        },
        dictOptions: {},
      }
    },
    created() {},
    computed: {
      importExcelUrl: function() {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      showImgModal(dynamic) {
        this.imgs = [];
        this.video = '';
        
        var dynamicStr = dynamic.dynamicImg;
        this.video = dynamic.dynamicVideo;
        if (dynamicStr != null && dynamicStr != '') {
          this.imgs = dynamicStr.split(",");
        }

        this.visible = true;
      },
      getAvatarView: function(avatar) {
        return getFileAccessHttpUrl(avatar)
      },
      initDictConfig() {},
      complaintsNPass(record) {
        //关小黑屋 
        this.axios.get('complaintManagement/complaintManagement/frozenDynamic', {
          params: {
            dynamicId: record.id
          }
        }).then((res) => {

          this.loadData();
        })
      },
      complaintsPass(record) {
        //放行
        this.axios.get('complaintManagement/complaintManagement/passDynamic', {
          params: {
            dynamicId: record.id
          }
        }).then((res) => {

          this.loadData();
        })
      },
      imgOk() {
        this.visible = false;
      },
      setRecommended(record) {
        var dynamicId = record.id;
        var status = "1";
        //设为推荐
        this.axios.get("/dynamic/dynamic/setRecommend", {
          params: {
            dynamicId: dynamicId,
            status: status
          }
        })
        this.loadData();
      },
      cancelRecommended(record) {
        var dynamicId = record.id;
        var status = "2";
        //设为推荐
        this.axios.get("/dynamic/dynamic/setRecommend", {
          params: {
            dynamicId: dynamicId,
            status: status
          }
        })
        this.loadData();
      },

      getDynamicInfo(record) {
        this.axios.get("/dynamic/dynamic/getDynamicInfo", {
          params: {
            dynamicId: record.id
          }
        }).then((res) => {
          this.dynamicInfo = res.result;
          //切割  图片
          if(this.forwradDynamicInfo.dynamicImg){
              this.imgs = this.forwradDynamicInfo.dynamicImg.split(",");
          }
          this.dynamicInfoVisible = true;
          this.forwradDynamicInfo = JSON.parse(res.result.isForWrad);
          console.log(this.forwradDynamicInfo);
        })
      },
      handleOk(e) {
        this.dynamicInfoVisible = false;
        this.dynamicInfo = {};
        this.imgs = [];
      },
      onChange(event,record){
        console.log("event:"+event);
        console.log("record:"+record.id);
        //2:通过   3:不通过
          if(event){
             record.audit = '2'
          }else{
             record.audit = '3';
          }
          this.axios.post('dynamic/dynamic/auditDynamic', record).then((res) => {
            this.loadData();
          })
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
